package cn.xx.org.controller;

import cn.xx.basic.util.AjaxResult;
import cn.xx.basic.util.PageList;
import cn.xx.org.domain.Department;
import cn.xx.org.domain.Shop;
import cn.xx.org.query.DepartmentQuery;
import cn.xx.org.query.ShopQuery;
import cn.xx.org.service.IShopService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/shop")
public class ShopController {
    @Autowired
    private IShopService iShopService;

    @PostMapping("/settlement")
    public AjaxResult settlement(@RequestBody Shop shop) {
        try {
            //商家入驻
            iShopService.settlement(shop);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }
    }
    //分页查询接口
    @PostMapping
    @ApiOperation(value = "分页查询",notes = "")
    public PageList<Shop> pageQuery(@RequestBody ShopQuery shopQuery) {

        return iShopService.pageQuery(shopQuery);
    }

    //修改为待激活
    @DeleteMapping("/{id}")
    @ApiOperation(value = "修改为待激活",notes = "")
    public AjaxResult setPass(@PathVariable("id") Long id) {
        try {
                if (id != null && !"".equals(id)) {
                    iShopService.setPass(id);
                }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }
    }

    //修改为被驳回
    @PutMapping("/setReturn")
    @ApiOperation(value = "修改为驳回",notes = "")
    public AjaxResult setReturn(@RequestBody Shop para) {
        try {
            iShopService.setReturn(para.getId(),para.getContent());
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }
    }

    //驳回原因被修改，状态变为为待激活
    @PutMapping("/setLoding")
    @ApiOperation(value = "驳回原因被修改，状态变为为待激活",notes = "")
    public AjaxResult setLoding(@RequestBody Shop para) {
        try {
            iShopService.setLoding(para.getId(),para);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }
    }

    //修改为正常
    @GetMapping("/{id}")
    @ApiOperation(value = "修改为正常",notes = "")
    public AjaxResult setOpen(@PathVariable Long id) {
        try {
            iShopService.setopen(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMsg(e.getMessage());
        }
    }
}
